<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>C++编码风格指南 | 惘客的个人博客</title>
  <meta name="description" content="本文记录关于个人在开发中比较喜欢的编码习惯。 编码方式项目中所有文件统一使用UTF-8编码。 命名约定通用约定 所有命名中不得出现中文 命名应该见名知意，避免晦涩难懂的缩写 所有名称尽可能保持在一个单词内 不要在使用以前那种在变量名称中体现其类型的前缀  目录命名全部采用小写字母，多个单词之间使用连字符”-“连接，如xxx-yyy。 项目命名全部采用小写字母，多个单词之间使用连字符”-“连接，如：">
<meta property="og:type" content="article">
<meta property="og:title" content="C++编码风格指南">
<meta property="og:url" content="https://gycherish.gitee.io/blog/posts/53c754a2.html">
<meta property="og:site_name" content="惘客的个人博客">
<meta property="og:description" content="本文记录关于个人在开发中比较喜欢的编码习惯。 编码方式项目中所有文件统一使用UTF-8编码。 命名约定通用约定 所有命名中不得出现中文 命名应该见名知意，避免晦涩难懂的缩写 所有名称尽可能保持在一个单词内 不要在使用以前那种在变量名称中体现其类型的前缀  目录命名全部采用小写字母，多个单词之间使用连字符”-“连接，如xxx-yyy。 项目命名全部采用小写字母，多个单词之间使用连字符”-“连接，如：">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-05-11T16:00:00.000Z">
<meta property="article:modified_time" content="2022-07-07T11:24:02.414Z">
<meta property="article:author" content="惘客">
<meta property="article:tag" content="develop">
<meta property="article:tag" content="c++">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="https://gycherish.gitee.io/blog/posts/53c754a2.html">
  
    <link rel="alternate" href="/atom.xml" title="惘客的个人博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.2.1"></head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://gitee.com/gycherish" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/head.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">惘客</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Linux C++ Server Developer</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Shanghai, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://gitee.com/gycherish" target="_blank" title="Gitee" data-toggle=tooltip data-placement=top><i class="icon icon-gitee"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      

    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/bios/" rel="tag">bios</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/c/" rel="tag">c++</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/cmake/" rel="tag">cmake</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/cpu/" rel="tag">cpu</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/develop/" rel="tag">develop</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/docker/" rel="tag">docker</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/dpdk/" rel="tag">dpdk</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/fs/" rel="tag">fs</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/" rel="tag">git</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hexo/" rel="tag">hexo</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/linux/" rel="tag">linux</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/lvm/" rel="tag">lvm</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/mbr/" rel="tag">mbr</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/os/" rel="tag">os</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/phabricator/" rel="tag">phabricator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/tmux/" rel="tag">tmux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/yum/" rel="tag">yum</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/bios/" style="font-size: 13px;">bios</a> <a href="/blog/tags/c/" style="font-size: 13px;">c++</a> <a href="/blog/tags/cmake/" style="font-size: 13px;">cmake</a> <a href="/blog/tags/cpu/" style="font-size: 13px;">cpu</a> <a href="/blog/tags/develop/" style="font-size: 14px;">develop</a> <a href="/blog/tags/docker/" style="font-size: 13px;">docker</a> <a href="/blog/tags/dpdk/" style="font-size: 13px;">dpdk</a> <a href="/blog/tags/fs/" style="font-size: 13.25px;">fs</a> <a href="/blog/tags/git/" style="font-size: 13.75px;">git</a> <a href="/blog/tags/hexo/" style="font-size: 13.5px;">hexo</a> <a href="/blog/tags/linux/" style="font-size: 13.5px;">linux</a> <a href="/blog/tags/lvm/" style="font-size: 13px;">lvm</a> <a href="/blog/tags/mbr/" style="font-size: 13px;">mbr</a> <a href="/blog/tags/os/" style="font-size: 13.25px;">os</a> <a href="/blog/tags/phabricator/" style="font-size: 13px;">phabricator</a> <a href="/blog/tags/tmux/" style="font-size: 13px;">tmux</a> <a href="/blog/tags/yum/" style="font-size: 13px;">yum</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/05/">五月 2022</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/04/">四月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/01/">一月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/08/">八月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/05/">五月 2021</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/03/">三月 2021</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/06/">六月 2020</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/05/">五月 2020</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/11/">十一月 2019</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/posts/dc0447d5.html" class="title">bios</a>
              </p>
              <p class="item-date">
                <time datetime="2022-05-17T09:35:00.000Z" itemprop="datePublished">2022-05-17</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/posts/57db9b5a.html" class="title">Intel处理器架构简介</a>
              </p>
              <p class="item-date">
                <time datetime="2022-05-16T07:05:00.000Z" itemprop="datePublished">2022-05-16</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/posts/7d606a33.html" class="title">高性能编程指南</a>
              </p>
              <p class="item-date">
                <time datetime="2022-04-07T09:30:00.000Z" itemprop="datePublished">2022-04-07</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/posts/7deb74e6.html" class="title">编译编译器</a>
              </p>
              <p class="item-date">
                <time datetime="2022-01-17T13:55:50.000Z" itemprop="datePublished">2022-01-17</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/posts/aa24c566.html" class="title">编写changelog</a>
              </p>
              <p class="item-date">
                <time datetime="2021-08-13T07:59:30.000Z" itemprop="datePublished">2021-08-13</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="post-Develop/C++编码风格指南" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      C++编码风格指南
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/posts/53c754a2.html" class="article-date">
	  <time datetime="2020-05-11T16:00:00.000Z" itemprop="datePublished">2020-05-12</time>
	</a>
</span>
        
        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/c/" rel="tag">c++</a>, <a class="article-tag-link" href="/blog/tags/develop/" rel="tag">develop</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/posts/53c754a2.html#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <p>本文记录关于个人在开发中比较喜欢的编码习惯。</p>
<h2 id="编码方式"><a href="#编码方式" class="headerlink" title="编码方式"></a>编码方式</h2><p>项目中所有文件统一使用UTF-8编码。</p>
<h2 id="命名约定"><a href="#命名约定" class="headerlink" title="命名约定"></a>命名约定</h2><h3 id="通用约定"><a href="#通用约定" class="headerlink" title="通用约定"></a>通用约定</h3><ul>
<li>所有命名中不得出现中文</li>
<li>命名应该见名知意，避免晦涩难懂的缩写</li>
<li>所有名称尽可能保持在一个单词内</li>
<li>不要在使用以前那种在变量名称中体现其类型的前缀</li>
</ul>
<h3 id="目录命名"><a href="#目录命名" class="headerlink" title="目录命名"></a>目录命名</h3><p>全部采用小写字母，多个单词之间使用连字符”-“连接，如xxx-yyy。</p>
<h3 id="项目命名"><a href="#项目命名" class="headerlink" title="项目命名"></a>项目命名</h3><p>全部采用小写字母，多个单词之间使用连字符”-“连接，如：</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">project</span>(chat-server)</span><br></pre></td></tr></table></figure>

<h3 id="目标名称"><a href="#目标名称" class="headerlink" title="目标名称"></a>目标名称</h3><p>所以可执行程序、静态库、动态库名称全部采用小写字母，多个单词之间使用连字符”-“连接，参考项目命名。</p>
<h3 id="类命名"><a href="#类命名" class="headerlink" title="类命名"></a>类命名</h3><p>采用大驼峰命名法，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ConnectionManager</span>;</span></span><br></pre></td></tr></table></figure>

<h3 id="文件命名"><a href="#文件命名" class="headerlink" title="文件命名"></a>文件命名</h3><h4 id="源文件"><a href="#源文件" class="headerlink" title="源文件"></a>源文件</h4><p>跟类名保持一致，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. 推荐方式</span></span><br><span class="line">connection_manager.h/cpp</span><br><span class="line"></span><br><span class="line"><span class="comment">// 2</span></span><br><span class="line">ConnectionManager.h/cpp</span><br></pre></td></tr></table></figure>

<p>如果某个文件内只是一些配置项的定义，则该文件使用小写命名，多个单词之间使用下划线连接，如：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">version.h</span><br><span class="line">config.h</span><br><span class="line">global.h</span><br><span class="line">constant.h</span><br></pre></td></tr></table></figure>

<h4 id="需要引起注意的文件"><a href="#需要引起注意的文件" class="headerlink" title="需要引起注意的文件"></a>需要引起注意的文件</h4><p>为了使这类文件看起来更显眼，全部使用大写字母，如以下文件：</p>
<ul>
<li>README.md</li>
<li>LICENSE</li>
<li>CHANGELOG.md</li>
</ul>
<h4 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h4><p>文件名使用全小写命名，多个单词使用下划线连接；配置项使用全小写命名，多个单词使用下划线连接，如：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">// config.ini</span><br><span class="line"><span class="attr">log_level</span>=debug</span><br><span class="line"><span class="attr">log_path</span>=/var/log</span><br></pre></td></tr></table></figure>

<h4 id="其他文件"><a href="#其他文件" class="headerlink" title="其他文件"></a>其他文件</h4><p>统一使用全小写命名，对于特殊文件，如.gitignore，则按照相应工具的要求命名。</p>
<h3 id="命名空间命名"><a href="#命名空间命名" class="headerlink" title="命名空间命名"></a>命名空间命名</h3><p>全部采用小写字母，多个单词使用下划线连接，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">namespace</span> xxx </span><br><span class="line">&#123;</span><br><span class="line"><span class="keyword">namespace</span> yyy &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">namespace</span> mmm_nnn &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h3 id="枚举命名"><a href="#枚举命名" class="headerlink" title="枚举命名"></a>枚举命名</h3><p>枚举名和枚举值全都使用大驼峰命名。全局作用域内的枚举为了避免命名冲突统一使用C++11的作用域枚举， 对于无法使用C++11的作用域枚举的情况，有两种方案可供选择:</p>
<ol>
<li>将枚举定义在命名空间内</li>
<li>在枚举值前面加上能够表示该枚举特征的前缀，前缀使用全大写且尽量使用较少的字符<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// C++11的作用域枚举</span></span><br><span class="line"><span class="keyword">enum</span> <span class="class"><span class="keyword">class</span> <span class="title">OSType</span> &#123;</span></span><br><span class="line">    Linux,</span><br><span class="line">    Windows</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 非作用域枚举: 方案1, 推荐方案</span></span><br><span class="line"><span class="keyword">namespace</span> OSType &#123; <span class="comment">// 此时命名空间命名不符合规则，可忽略</span></span><br><span class="line">    <span class="keyword">enum</span> OSType &#123;</span><br><span class="line">        Linux,</span><br><span class="line">        Windows</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 非作用域枚举: 方案2</span></span><br><span class="line"><span class="keyword">enum</span> OSType &#123;</span><br><span class="line">    OSLinux,</span><br><span class="line">    OSWindows</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h3 id="函数命名"><a href="#函数命名" class="headerlink" title="函数命名"></a>函数命名</h3><p>采用小驼峰命名法，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">testFunc</span><span class="params">()</span></span>;</span><br></pre></td></tr></table></figure>

<h3 id="变量命名"><a href="#变量命名" class="headerlink" title="变量命名"></a>变量命名</h3><h4 id="全局变量"><a href="#全局变量" class="headerlink" title="全局变量"></a>全局变量</h4><p>使用“g_”前缀加小驼峰命名法，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> g_count;</span><br><span class="line"><span class="keyword">static</span> <span class="built_in">std</span>::<span class="built_in">string</span> g_name;</span><br><span class="line">ConnectionManager g_connMgr;</span><br></pre></td></tr></table></figure>

<h4 id="常量"><a href="#常量" class="headerlink" title="常量"></a>常量</h4><p>对于全局常量，统一使用大写字母加下划线方式，对于内部使用的常量可以使用枚举来定义，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> BUFFER_SIZE = <span class="number">4096</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">char</span> DEFAULT_PATH[] = <span class="string">"/tmp"</span>;</span><br></pre></td></tr></table></figure>

<h4 id="成员变量"><a href="#成员变量" class="headerlink" title="成员变量"></a>成员变量</h4><p>使用“m_”前缀加小驼峰命名法，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">m_testX;</span><br></pre></td></tr></table></figure>
<p>也有喜欢使用加后缀“_”的方式，但是这种方式不利于代码补全，而使用前者则可以在打出“m_”后很方便的看到所有成员变量。</p>
<h3 id="宏命名"><a href="#宏命名" class="headerlink" title="宏命名"></a>宏命名</h3><p>使用大写字母加下划线方式，对于函数宏建议使用inline函数代替，对于值类型的宏建议使用枚举代替，而且用枚举还能限定作用域，而宏是在编译预处理阶段被替换，还没到编译阶段，因此所有宏都无法指定作用域，如：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> MAX(x, y) ((x) &gt; (y) ? (x) : (y)) <span class="comment">// 可使用inline函数</span></span></span><br><span class="line"><span class="comment">// 使用inline函数替换</span></span><br><span class="line"><span class="function"><span class="keyword">inline</span> <span class="keyword">int</span> <span class="title">max</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> x &gt; y ? x : y;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> MAX_SIZE 100</span></span><br><span class="line"><span class="comment">// 使用常量替换</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> MAX_SIZE = <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> CODE_OK 0</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> CODE_FAIL -1</span></span><br><span class="line"><span class="comment">// 使用枚举替换</span></span><br><span class="line">enmu <span class="class"><span class="keyword">class</span> <span class="title">ReturnCode</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    Ok = <span class="number">0</span>,</span><br><span class="line">    Fail = <span class="number">-1</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>宏定义一般只在需要控制编译、跨平台方面使用，因为这块的功能其他方式无法替代宏定义。</p>
<h3 id="其他命名"><a href="#其他命名" class="headerlink" title="其他命名"></a>其他命名</h3><h4 id="自定义-cmake-模块"><a href="#自定义-cmake-模块" class="headerlink" title="自定义 cmake 模块"></a>自定义 cmake 模块</h4><p>模块文件名采用大驼峰命名，模块中的函数采用全校小命名，多个单词使用下划线链接，如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 模块名</span><br><span class="line">SetRuntimeDir.cmake</span><br><span class="line"># 内部的函数名</span><br><span class="line">set_runtime_dir()</span><br></pre></td></tr></table></figure>


<h2 id="头文件保护"><a href="#头文件保护" class="headerlink" title="头文件保护"></a>头文件保护</h2><h3 id="define-保护"><a href="#define-保护" class="headerlink" title="#define 保护"></a>#define 保护</h3><p>格式：PROJECT_MODULE_FILE_H，例如muduo库中的Buffer类的头文件：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">ifndef</span> MUDUO_NET_BUFFER_H</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> MUDUO_NET_BUFFER_H</span></span><br><span class="line"><span class="comment">// code</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span> <span class="comment">// MUDUO_NET_BUFFER_H</span></span></span><br></pre></td></tr></table></figure>

<h3 id="pragma-保护"><a href="#pragma-保护" class="headerlink" title="#pragma 保护"></a>#pragma 保护</h3><p>推荐方式:</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> once</span></span><br><span class="line"><span class="comment">// code</span></span><br></pre></td></tr></table></figure>

<h3 id="include-顺序"><a href="#include-顺序" class="headerlink" title="#include 顺序"></a>#include 顺序</h3><p>避免在当前模块引入隐含的依赖，采用一下顺序作为头文件的包含顺序：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 类自身的头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"foo.h"</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 项目当前模块的其他头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"bar.h"</span></span></span><br><span class="line"><span class="comment">// 项目其他模块的头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"other/tool.h"</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 三方库头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;asio.hpp&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">// c++头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="comment">// c头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string.h&gt;</span></span></span><br><span class="line"><span class="comment">// 系统头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;sys/stat.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;sys/time.h&gt;</span></span></span><br></pre></td></tr></table></figure>

<h3 id="前置申明"><a href="#前置申明" class="headerlink" title="前置申明"></a>前置申明</h3><p>为了减少编译时的依赖，提高项目编译速度，头文件中使用到的类应该尽可能地使用前置申明。能够使用前置申明的核心原理：</p>
<ul>
<li>当前头文件没有使用到依赖类型的任何成员</li>
<li>依赖类型不影响当前类型的大小</li>
</ul>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// a.h</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">A</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">int</span> data;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">func</span><span class="params">()</span></span>;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">// b.h:  针对情况1、2、3都可以使用前置什么</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>;</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">B</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    A* a1; <span class="comment">// 1. 指针大小固定，A的类型不影响B的大小</span></span><br><span class="line">    A&amp; a2; <span class="comment">// 2. 引用大小固定，A的类型不影响B的大小 </span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 3. 参数虽然是值类型，但是类的所有成员函数不影响类的大小，且头文件不含有该函数的</span></span><br><span class="line">    <span class="comment">// 定义，即没有使用到A的任何成员</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">func</span><span class="params">(A a)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="格式"><a href="#格式" class="headerlink" title="格式"></a>格式</h2><h3 id="代码缩进"><a href="#代码缩进" class="headerlink" title="代码缩进"></a>代码缩进</h3><ol>
<li>统一使用空格进行代码缩进，缩进宽度为4个 ascii 字符宽度。</li>
<li>若使用 Tab 进行缩进，则需要设置 Tab 为4个 ascii 字符宽度，且转为空格。</li>
</ol>
<h3 id="空格的使用"><a href="#空格的使用" class="headerlink" title="空格的使用"></a>空格的使用</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. 双/三目运算符，操作符和操作数之间加空格</span></span><br><span class="line"><span class="keyword">int</span> a = b + c;</span><br><span class="line"><span class="keyword">int</span> a = b &gt; c ? b : c;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 2. 函数参数和花括号之间加空格</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">func</span><span class="params">(arg)</span> </span>&#123;&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 3. 其他条件，循环等语句，关键字、()、&#123;&#125;之间加空格</span></span><br><span class="line"><span class="keyword">if</span> () &#123;&#125;</span><br><span class="line"><span class="keyword">while</span> () &#123;&#125;</span><br><span class="line"><span class="keyword">switch</span> () &#123;&#125;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 4. 其他类似情况</span></span><br></pre></td></tr></table></figure>

<h3 id="花括号"><a href="#花括号" class="headerlink" title="花括号"></a>花括号</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Test</span></span></span><br><span class="line"><span class="class">&#123;</span> <span class="comment">// 类级别换行</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">func</span><span class="params">()</span> </span>&#123; <span class="comment">// 类内部实现不换行</span></span><br><span class="line">        <span class="keyword">if</span> () &#123; <span class="comment">// 函数内部代码块不换行</span></span><br><span class="line">        </span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> &#123; <span class="comment">//  函数内部代码块不换行</span></span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">void</span> func()</span><br><span class="line">&#123; <span class="comment">// 类外部实现换行</span></span><br><span class="line">    <span class="keyword">while</span> () &#123; <span class="comment">// 函数内部代码块不换行</span></span><br><span class="line">    </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">switch</span> () &#123; <span class="comment">// 函数内部代码块不换行</span></span><br><span class="line">    <span class="keyword">case</span> x: &#123; <span class="comment">// 函数内部代码块不换行</span></span><br><span class="line">    </span><br><span class="line">    &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">for</span> () &#123; <span class="comment">// 函数内部代码块不换行</span></span><br><span class="line">    </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>以上情况，对于只有单行语句的也建议添加{}。</p>
<h3 id="函数参数过多"><a href="#函数参数过多" class="headerlink" title="函数参数过多"></a>函数参数过多</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 当参数超过3个时可考虑将后续参数换行，并将换行的参数和第一个参数对齐</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">func</span><span class="params">(Type arg1, Type arg2, Type arg3, </span></span></span><br><span class="line"><span class="function"><span class="params">          Type arg4, Type arg5, Type arg6)</span></span></span><br></pre></td></tr></table></figure>

<h2 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h2><p>统一使用<a href="http://www.doxygen.nl/" target="_blank" rel="noopener">Doxygen</a>文档注释风格。</p>
<h2 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h2><ul>
<li><a href="https://llvm.org/docs/CodingStandards.html#include-style" target="_blank" rel="noopener">LLVM include style</a></li>
<li><a href="https://wiki.qt.io/Qt_Coding_Style/zh" target="_blank" rel="noopener">Qt code style</a></li>
<li><a href="https://webkit.org/code-style-guidelines/" target="_blank" rel="noopener">Webkit code style</a></li>
</ul>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="https://gycherish.gitee.io/blog/posts/53c754a2.html" title="C++编码风格指南" target="_blank" rel="external">https://gycherish.gitee.io/blog/posts/53c754a2.html</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://gitee.com/gycherish" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/head.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://gitee.com/gycherish" target="_blank"><span class="text-dark">惘客</span><small class="ml-1x">Linux C++ Server Developer</small></a></h3>
        <div>宁静致远，淡泊明志！</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/posts/a26991f5.html" title="DPDK编译"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/posts/eaf73cc8.html" title="基于Hexo_Gitee的博客系统搭建"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/alipay.jpg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/wechatpay.jpg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://gitee.com/gycherish" target="_blank" title="Gitee" data-toggle=tooltip data-placement=top><i class="icon icon-gitee"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2024 惘客
        
        <!-- <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div> -->
        <div class="police">
            <img src="/blog/images/beian.png" style="float:left;" /><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=41152702000156" target="_blank">豫公网安备41152702000156号</a>
        </div>
        <div class="beianinfo">
            <a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2021012829号</a>
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   







<!-- 添加回到顶部按钮 -->
<div id="go-top"></div>
<style type="text/css">
#go-top {
 width:40px;height:40px;
 background-color:#8cc2ff;
 position:relative;
 border-radius:20px;
 position:fixed;right:10px;bottom:60px;
 cursor:pointer;display:none;
}
#go-top:after {
 content:" ";
 position:absolute;left:14px;top:14px;
 border-top:2px solid #fff;border-right:2px solid #fff;
 width:12px;height:12px;
 transform:rotate(-45deg);
}
#go-top:hover {
 background-color:#8A2BE2;
}
</style>
<script>
$(function () {
  var top=$("#go-top");
  $(window).scroll(function () {
    ($(window).scrollTop() > 300) ? top.show(300) : top.hide(200);
    $("#go-top").click(function () {
      $('body,html').animate({scrollTop:0});
      return false();
    })
  });
});
</script>
</body>
</html>